package com.iotproject.studyservice.service.impl;

import com.iotproject.studyservice.entity.UserUnrememberWord;
import com.iotproject.studyservice.entity.vo.UnrememberWord;
import com.iotproject.studyservice.mapper.UserUnrememberWordMapper;
import com.iotproject.studyservice.service.StudyWordService;
import com.iotproject.studyservice.service.UserUnrememberWordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 用户生词本 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-04-07
 */
@Service
public class UserUnrememberWordServiceImpl extends ServiceImpl<UserUnrememberWordMapper, UserUnrememberWord> implements UserUnrememberWordService {

    @Autowired
    StudyWordService studyWordService;

    @Override
    public void insertUserUnrememberWord(String wordId, String grade, HttpServletRequest httpServletRequest) {
        String memberUserId = studyWordService.getMemberUserId(httpServletRequest);
        QueryWrapper<UserUnrememberWord> userUnrememberWordQueryWrapper = new QueryWrapper<>();
        userUnrememberWordQueryWrapper.eq("user_id", memberUserId);
        userUnrememberWordQueryWrapper.eq("unremember_word_id", wordId);
        UserUnrememberWord userUnrememberWord = baseMapper.selectOne(userUnrememberWordQueryWrapper);
        if (userUnrememberWord == null) {//插入数据
            userUnrememberWord = new UserUnrememberWord();
            userUnrememberWord.setUserId(memberUserId);
            userUnrememberWord.setUnrememberWordId(wordId);
            userUnrememberWord.setGrade(grade);
            baseMapper.insert(userUnrememberWord);
        }
    }

    @Override
    public List<UnrememberWord> getUserUnrememberWordList(String userId, String grade) {
        List<UnrememberWord> userUnrememberWordList = baseMapper.getUserUnrememberWordList(userId, grade);
        return userUnrememberWordList;
    }
}
